﻿using System;
using System.Globalization;
using Dpx.Models;
using Dpx.Util;
using Xamarin.Forms;

namespace Dpx.Converters {
    /// <summary>
    /// 诗词缩进转换器。
    /// </summary>
    public class PoetryIndentConverter : IValueConverter {
        public object Convert(object value, Type targetType, object parameter,
            CultureInfo culture) {
            if (!(value is Poetry poetry)) {
                return null;
            }

            return poetry.Layout == Poetry.IndentLayout
                ? poetry.Content.Insert(0, "\u3000\u3000")
                    .Replace("\n", "\n\u3000\u3000")
                : poetry.Content;
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo culture) {
            throw new DoNotCallThisException();
        }
    }
}